﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Testing
{
    public partial class UserInfo : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                //if(Request.QueryString["uid"]!=null)
                //{
                //    string uId = Request.QueryString["uid"].ToString();
                //    DataBindDetail(uId);
                //}
                
                bindUser();
            }
        }

        private void bindUser()
        {
            gvMain.DataSource = BLL.UserInfoBLL.Instance.GetList();
            gvMain.DataBind();
        }
        //register
        protected void regist_Click(object sender, EventArgs e)
        {
            Model.UserInfo user = new Model.UserInfo();
            user.UserID = Guid.NewGuid().ToString();
            user.Email = email.Text.Trim();
            user.UserName = userName.Text.Trim();
            user.Password = EncryptMD5(password.Text.Trim());
            user.RoleID = "visitor";
            user.State = 0;
            string userID = string.Empty;
            string result = BLL.UserInfoBLL.Instance.FirstStepOfRegister(user, out userID);
            Message.Text = result;
            bindUser();
        }
        //activate
        protected void active_Click(object sender, EventArgs e)
        {
            //BLL.UserInfoBLL.Instance.Activate(userID.Text.Trim());
            bindUser();
        }
        //login
        protected void login_Click(object sender, EventArgs e)
        {
            Model.UserInfo user = BLL.UserInfoBLL.Instance.Login(loginName.Text.Trim(), EncryptMD5(loginPsw.Text.Trim()));
            if (user != null)
            {
                base.VerifiedInfo = new AUV5.Model.VerifiedInfo(user);
            }
            if (base.VerifiedInfo != null)
            {
                Response.Redirect("ServiceInfo.aspx");
            }
            else
            {
                Message.Text = "Login Fail!";
            }
        }
    }
}